﻿using Bot.Salesforce.Model;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Polly.Caching;
using Polly.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bot.Salesforce.Configure
{
    public static class SalesforceConfigure
    {
        public static IServiceCollection AddSalesforceService(this IServiceCollection services, IConfiguration configuration, IWindsorContainer iocContainer)
        {
            services.Configure<SalesforceSetting>(configuration);
            iocContainer.Register(Component.For<ISalesforceService>().ImplementedBy<SalesforceService>().LifestyleTransient());
            iocContainer.Register(Component.For<ITokenService>().ImplementedBy<TokenService>().LifestyleTransient());
            iocContainer.Register(Component.For<IWebRequestService>().ImplementedBy<WebRequestService>().LifestyleTransient());
            iocContainer.Register(Component.For<IMemoryCache>().Instance(new MemoryCache(new MemoryCacheOptions())).LifestyleSingleton()); 
            iocContainer.Register(Component.For<IAsyncCacheProvider>().ImplementedBy<MemoryCacheProvider>().LifestyleSingleton()); 
            return services;
        }
    }
}
